/**
 * 路由
 * @author xiaoqiang <465633678@qq.com>
 * @created 2018/11/02 10:38:16
 */
const Router = require('koa-router')
const path = require('path')
const uploadFile = require('../utils/upload')

const router = new Router()
/**
 * 首页路由
 */
router.get('/', async (ctx) => {
  /**
   * 渲染首页
   * index.html
   */
  await ctx.render('index', {
    title: '首页'
  })
})
/**
 * 上传路由
 */
router.post('/upload', async (ctx) => {
  /**
   * 调用上传方法
   * 获取上传结果
   */
  const content = await uploadFile(ctx, {
    path: path.join(__dirname, '../upload'),
    fileType: 'image'
  })
  ctx.body = content
})

module.exports = router